package com.bolins.util;

public class GetLastDayOfMonth {

	/**
	 * 判断是否是闰年
	 * 
	 * @param year
	 * @return
	 */
	public boolean isLeapyear(int year) {

		boolean leapyear = false;

		if (year % 100 == 0 && year % 400 == 0) {
			leapyear = true;
		} else if (year % 4 == 0) {
			leapyear = true;
		}

		return leapyear;
	}

	/**
	 * 得到当前月最后一天
	 * 
	 * @param year
	 * @param month
	 * @return
	 */
	public int getLastDayOfMonth(int year, int month) {

		boolean leapyear = this.isLeapyear(year);

		int lastday = 0;
		switch (month) {

		case 1:
			lastday = 31;
			break;
		case 2:
			lastday = 28;
			break;
		case 3:
			lastday = 31;
			break;
		case 4:
			lastday = 30;
			break;
		case 5:
			lastday = 31;
			break;
		case 6:
			lastday = 30;
			break;
		case 7:
			lastday = 31;
			break;
		case 8:
			lastday = 31;
			break;
		case 9:
			lastday = 30;
			break;
		case 10:
			lastday = 31;
			break;
		case 11:
			lastday = 30;
			break;
		case 12:
			lastday = 31;
			break;

		}

		if (leapyear && month == 2)
			lastday = 29;
		return lastday;

	}

	public String getEndTime(int year, int month) {

		String endtime = "";
		int lastday = this.getLastDayOfMonth(year, month);
		endtime = year + "-" + month + "-" + lastday + " " + "23:59:59";
		return endtime;
	}

}
